import matplotlib.pyplot as plt
import numpy as np

# 设置中文显示
plt.rcParams["font.family"] = ["WenQuanYi Micro Hei"]
plt.rcParams["axes.unicode_minus"] = False  # 正确显示负号

# 示例数据 - 替换为你的实际坐标点
line1_str = "(-125.674,-40.2178) (-125.767,-40.7355) (-125.796,-41.7314) (-125.773,-42.3225) (-125.714,-43.171) (-125.659,-43.6925) (-125.569,-44.1969) (-125.252,-44.6937) (-124.518,-44.8801) (-123.926,-44.923) (-122.951,-44.9579) (-122.102,-44.9725) (-121.597,-44.9772) (-120.792,-44.9803) (-120.361,-44.9804) (-119.585,-44.9793) (-119.081,-44.9781) (-118.731,-44.9771) (-118.001,-44.9748) (-117.243,-44.9723) (-116.273,-44.969)"
line2_str = "(-125.671,-40.2185) (-125.671,-40.2191) (-125.672,-40.2226) (-125.673,-40.232) (-125.677,-40.2498) (-125.683,-40.2781) (-125.692,-40.3191) (-125.703,-40.3744) (-125.717,-40.4456) (-125.734,-40.5339) (-125.752,-40.6405) (-125.769,-40.7661) (-125.784,-40.9115) (-125.795,-41.077) (-125.8,-41.2624) (-125.801,-41.4673) (-125.796,-41.6905) (-125.789,-41.9306) (-125.779,-42.1864) (-125.765,-42.4566) (-125.748,-42.7396) (-125.726,-43.0332) (-125.697,-43.3352) (-125.664,-43.6422) (-125.625,-43.9504)"
points1 = [(float(tup_str.split(',')[0][1:]), float(tup_str.split(',')[1][:-1])) for tup_str in line1_str.split(' ')]  # 第一组坐标点
points2 = [(float(tup_str.split(',')[0][1:]), float(tup_str.split(',')[1][:-1])) for tup_str in line2_str.split(' ')]  # 第二组坐标点

# 将坐标点拆分为x和y列表
x1, y1 = zip(*points1)  # 解包第一组点
x2, y2 = zip(*points2)  # 解包第二组点

# 按x值排序（确保曲线正确连接）
sorted1 = sorted(zip(x1, y1))  # 按x值排序第一组点
sorted2 = sorted(zip(x2, y2))  # 按x值排序第二组点

# 重新获取排序后的x和y
x1_sorted, y1_sorted = zip(*sorted1)
x2_sorted, y2_sorted = zip(*sorted2)

# 创建图形
plt.figure(figsize=(10, 6))

# 绘制第一条曲线
plt.plot(x1_sorted, y1_sorted, 
         'o-',          # 圆形标记+实线连接
         color='royalblue',
         linewidth=2,
         markersize=8,
         label='全局路径')

# 绘制第二条曲线
# plt.plot(x2_sorted, y2_sorted, 
#          's--',         # 方形标记+虚线连接
#          color='crimson',
#          linewidth=2,
#          markersize=8,
#          label='规划路径')

# 添加数据点标签（可选）
# for x, y in points1:
#     plt.text(x, y+0.1, f'({x},{y})', 
#              ha='center', va='bottom', 
#              fontsize=9, color='royalblue')

# for x, y in points2:
#     plt.text(x, y-0.2, f'({x},{y})', 
#              ha='center', va='top', 
#              fontsize=9, color='crimson')

# 添加标题和标签
plt.title('两组坐标点曲线对比', fontsize=14, pad=20)
plt.xlabel('X坐标', fontsize=12)
plt.ylabel('Y坐标', fontsize=12)

# 添加图例和网格
plt.legend(fontsize=12)
plt.grid(True, linestyle=':', alpha=0.6)

# 自动调整坐标轴范围
plt.autoscale(enable=True, axis='both', tight=True)

# 显示图形
plt.tight_layout()
plt.show()